<?php
/**
 * User: lsx
 * Date: 2017/4/27
 * Time: 9:31
 * Progress:0%
 */

namespace app\index\controller;



use icontroller\admin\AController;
use icontroller\admin\index\IAdminRole;

use library\common\collections\ArrayUtils;
use logic\admin\index\LAdminRole;
use think\Db;

class AdminRole extends AController implements IAdminRole
{
    private $logic;
    public function __construct()
    {
        parent::__construct();
        $this->logic=new LAdminRole();
    }

    public function index()
    {
        return view();
    }

    public function index_data(){
        $param=array(
            'keyword'=>input('keyword'),
            'limit'=>input('limit'),
            'offset'=>input('offset'),
            'ordinal'=>input('ordinal'),
            'order'=>input('order'),
        );
        return $this->logic->index_data($param);
    }

    public function add()
    {
        return view();
    }

    public function insert()
    {
       $param=array(
           'name'=>input('name'),
           'flag_lock'=>input('flag_lock'),
           'remark'=>input('remark')
       );
        return $this->logic->insert_data($param);
    }

    public function edit()
    {
        $id=input('id');
        $data=$this->logic->edit_data($id);
        $this->assign('data',$data);
       return view();
    }

    public function update()
    {
        $id=input('id');
        $param=array(
            'name'=>input('name'),
            'remark'=>input('remark'),
            'flag_lock'=>input('flag_lock')
        );
        return $this->logic->update_data($id,$param);
    }

    public function delete()
    {
        $id=input('id');
        return $this->logic->delete_data($id);
    }

    function power()
    {
        $id=input('id');
        $check=Db::name('admin_role')->where(['id'=>$id])->find();
        $powers=$check['powers_show'];
        $powers_show=array();
        if($powers){
            $powers_show=explode(',',$powers);
        }
        $this->assign('rules',json_encode($powers_show));
        $data=$this->logic->power_index($id);
        $this->assign('role_id',$id);
        $this->assign('powers_show',$data['powers_show_arr']);
        $this->assign('data',$data['data']);
        return view();
    }

    function power_update()
    {
//        var_dump(input('rules'));die();
//        var_dump(1111);
//        var_dump(input('timeout'));die();
        $id=input('role_id');
        $powers_show=input('rules');
        $param=array(
            'powers_show'=>$powers_show,
            'powers'=>input('powers/a'),
        );
        return $this->logic->power_update($id,$param);
    }
}